package edu.xlh.travel.controller.admin;

import com.fasterxml.jackson.core.JsonProcessingException;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.OnlineUserInfo;
import edu.xlh.travel.pojo.querypojo.QueryOnlineUserInfo;
import edu.xlh.travel.service.OnlineUserInfoService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/onlineUserInfo")
public class OnlineUserInfoController {

    @Autowired
    private OnlineUserInfoService onlineUserInfoService;

    /*
    * to onlineUserInfoList page
    * */
    @Log("跳转在线用户列表页面")

    @RequestMapping("/onlineUserInfoList")
    public String onlineUserList() {
        return "admin/systemMonitoring/onlineUserList";
    }

   /*
   * save onlineUserInfo when logning
   * */
   @Log("保存在线用户")
   @RequestMapping("/save")
    @ResponseBody
    public Result save(HttpServletRequest request, HttpSession session) throws JsonProcessingException {
        return onlineUserInfoService.save(request , session);
    }

    /*
    * findAllOnlineUserInfo
    * */
    @Log("查询所有的在线用户")
    @RequestMapping("/findAllOnlineUserInfo")
    @ResponseBody
    public Result findAllOnlineUserInfo(int page, int limit , HttpSession session) {
        return onlineUserInfoService.findAllOnlineUserInfo(page , limit , session);
    }
    /*@RequestMapping("/operatedLogList")
    public String operatedLogList() {
        return "admin/systemMonitoring/operatedLogList";
    }*/

    /*
    * query onlineUser by condition
    * */
    @Log("条件模糊查询在线用户")
    @RequestMapping("/QueryOnlineUserByCondition")
    @ResponseBody
    public Result QueryOnlineUserByCondition(Integer page, Integer limit , QueryOnlineUserInfo queryOnlineUserInfo , HttpSession session) {
        return onlineUserInfoService.QueryOnlineUserByCondition(page, limit , queryOnlineUserInfo , session);
    }

    @Log("根据用户id强退管理员")
    @RequestMapping("/forceLoginOut/{userId}")
    @ResponseBody
    public Result forceLoginOut(@PathVariable("userId") String userId , HttpServletRequest request  , HttpSession session) {
        return onlineUserInfoService.forceLoginOut(userId , request , session);
    }

    @Log("活跃状态判断")
    @RequestMapping("/isActive")
    @ResponseBody
    public Result isActive(HttpSession session) {
        return onlineUserInfoService.isActive( session);
    }
}
